<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <el-form-item>
          <div class="balance-searchMoney">
            结算单号
            <el-input class="input" v-model="dataForm.userName" placeholder="请输入结算单号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            结算日期
            <el-date-picker v-model="value" :clearable='false' type="daterange" value-format="yyyy-MM-dd HH:mm:ss" class="input" start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <!-- <el-form-item>
          <div class="balance-searchMoney">
            结算单位
            <el-select v-model="value1" clearable @change="cityCode" filterable placeholder="请选择">
              <el-option v-for="item in city" :key="item.legalAccountCode" :label="item.legalCompanyName" :value="item.legalAccountCode">
              </el-option>
            </el-select>
          </div>
        </el-form-item> -->
      </div>
      <el-form-item>
        <div class="balance-searchMoney">
          结算单位
          <el-select v-model="value1" filterable placeholder="请选择">
            <el-option v-for="item in city" :key="item.legalAccountCode" :label="item.legalCompanyName" :value="item.legalAccountCode">
            </el-option>
          </el-select>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="demand">查询</el-button>
        <el-button type="primary" @click="empty">清空</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color" style="width: 100%;">
      <template slot="empty">
        <img class="machine" src="../../assets/img/machine.svg" alt="" />
        <div style="font-size: 14px; text-align: center">暂无数据</div>
      </template>
      <el-table-column prop="cycleNo" header-align="center" align="center" label="结算单号" width="160px">
      </el-table-column>
      <!-- <el-table-column prop="" header-align="center" align="center" label="结算时间" width="200" :render-header="renderHeader">
        <template slot-scope="scope">
          <div size="small" type="danger">
            {{ scope.row.settlementTime  }}
          </div>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="" header-align="center" align="center" label="结算周期">
        <template slot-scope="scope">
          <div size="small" type="danger">
            T+{{ scope.row.settlementInterval }}
          </div>
        </template>
      </el-table-column> -->
      <el-table-column prop="" header-align="center" align="center" label="结算日期" width="160px" :render-header="renderHeader">
        <template slot-scope="scope">
          <div size="small" type="danger">
            {{ scope.row.settlementTime  }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="cycleTotalFee" header-align="center" align="center" label="账单金额(元)" width="160px">
        <template slot-scope="scope">
          <div size="small" type="danger">
            {{ scope.row.cycleTotalFee| MoneyFormat }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="serviceCharge" header-align="center" align="center" label="支付手续费(元)" width="120px">
        <template slot-scope="scope">
          <div>{{ scope.row.serviceCharge| MoneyFormat }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="actualCycleFee" header-align="center" align="center" label="结算金额(元)" width="120px">
        <template slot-scope="scope">
          <div>{{ scope.row.actualCycleFee| MoneyFormat }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="status" header-align="center" align="center" label="结算状态">
        <template slot-scope="scope">
          <div v-if="scope.row.settlementStatus === 0" size="small" type="danger" class="blueMoney">
            未结算
          </div>
          <div v-else size="small" class="greenMoney">已结算</div>
        </template>
      </el-table-column>
      <el-table-column prop="withdrawStatus" header-align="center" align="center" width="100" label="提现状态">
        <template slot-scope="scope">
          <div v-if="scope.row.withdrawStatus === 0" class="orangeMoney">
            未提现
          </div>
          <div v-if="scope.row.withdrawStatus === 1" class="greenMoney">
            提现中
          </div>
          <div v-if="scope.row.withdrawStatus === 2" class="grayMoney">
            已提现
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="legalCompanyName" header-align="center" align="center" label="结算单位" width="120">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="100" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.cycleNo)">账单详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <div>
      <div style="margin-bottom:15px;">注： 1、结算金额=账单金额-退款结算金额-支付手续费</div>
      <div>2、结算金额仅作为结算统计参考，实际收到的款项以提现记录为准</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        userName: "",
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      value: "",
      legalAccountCode: "",
      cycleNo: "",
      startSettlementCycle: "",
      endSettlementCycle: "",
      endPaymentTime: "",
      startPaymentTime: "",
      city: [],
      value1: "",
    };
  },
  activated () {
    this.cycleNo = this.$route.query.cycleNo;
    this.getDataList();
    this.cityList();
  },
  methods: {
    // 表格头部提示事件
    renderHeader (h, { column }) {
      return h("span", [
        h("span", column.label),
        h(
          "el-tooltip",
          {
            props: {
              effect: "dark",
              content: "根据系统设置的结算周期，T+N结算账单金额的时间",
              placement: "top",
            },
          },
          [
            h("i", {
              class: "el-icon-question",
              style: "color:#000;margin-left:5px;",
            }),
          ],
          {
            content: "根据系统设置的结算周期，T+N结算账单金额的时间",
          }
        ),
      ]);
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/settlementBill/list"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.legalAccountCode ? this.legalAccountCode : "",
          cycleNo: this.cycleNo,
          startSettlementCycle: this.startSettlementCycle,
          endSettlementCycle: this.endSettlementCycle,
        }),
      }).then(({ data }) => {
        console.log(data)
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 获取数据列表
    cityList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/legalCompany/getByCurrentFinanceCode"
        ),
        method: "get",
        params: this.$http.adornParams({}),
      }).then(({ data }) => {
        if (data.success == 1) {
          console.log(data);
          this.city = data.data;
        } else {
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("cassadmin/v1/settlementBill/list"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          legalAccountCode: this.value1,
          cycleNo: this.dataForm.userName,
          startSettlementCycle: this.value[0] || '',
          endSettlementCycle: this.value[1] || '',
        }),
      }).then(({ data }) => {
        console.log(data)
        if (data.success == 1) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false
      });
    },
    //清空
    empty () {
      this.dataForm.userName = ''
      this.value = ''
      this.value1 = ''
      this.getDataList()
    },
    // 查看详情
    addOrUpdateHandle (cycleNo) {
      this.$router.push({
        name: `totalFinance-Grouppropertylist`,
        query: {
          cycleNo: cycleNo,
        },
      });
    },
  },
};
</script>
<style scoped>
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
</style>
